package com.cloudfun.campusshare.entity;

import com.cloudfun.campusshare.common.constant.PromotionStatus;
import com.cloudfun.campusshare.common.constant.PromotionType;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.List;

/**
 * Created by Huqin on 2020/6/6
 */
@Data
@Entity
@Table(name = "promotion")
@org.hibernate.annotations.Table(appliesTo = "promotion", comment = "优惠活动")
public class PromotionEntity extends CreatorPersistenceEntity {

    @Id
    @GenericGenerator(name = "id_uuid", strategy = "uuid")
    @GeneratedValue(generator = "id_uuid")
    @Column(unique = true, columnDefinition = ("varchar(40) not null comment '主键uuid'"))
    private String id;

    @Column(unique = true, columnDefinition = ("varchar(32) not null comment '活动编号'"))
    private String promotionNo;

    @Column(name = "wash_point_id", columnDefinition = ("varchar(40) not null comment '洗衣点id'"))
    private String washPointId;

    @ManyToOne
    @JoinColumn(name = "wash_point_id", insertable = false, updatable = false)
    private WashPointEntity washPoint;

    @Column(columnDefinition = "varchar(32) not null comment '优惠类型'")
    @Enumerated(EnumType.STRING)
    private PromotionType type;

    @Column(columnDefinition = "varchar(64) not null comment '名称'")
    private String name;

    @Column(columnDefinition = ("datetime not null comment '活动开始时间'"))
    private LocalDateTime startTime;

    @Column(columnDefinition = ("datetime not null comment '活动结束时间'"))
    private LocalDateTime endTime;

    @Column(columnDefinition = "varchar(32) not null comment '状态'")
    @Enumerated(EnumType.STRING)
    private PromotionStatus status;

    @Column(columnDefinition = ("varchar(40) not null comment '所属商户Id'"))
    private String merchantId;

    @OneToMany(mappedBy = "promotion")
    private List<PromotionProductType> productTypes;

}
